Title: SQL W3S (By-BKK) / 032 Union All
Tags: Obsidian_to_Anki

Q: What does the SQL UNION ALL operator do?
A: It combines the result-set of two or more SELECT statements, including all duplicates

Q: Does UNION ALL remove duplicate rows?
A: No, UNION ALL includes all duplicates

Q: True or False: UNION ALL and UNION behave the same with duplicates
A: False

Q: What are the requirements for SELECT statements using UNION ALL?
A: Each SELECT must have the same number of columns with similar data types and same order

Q: Do column names in UNION ALL results come from the first SELECT statement?
A: Yes

Q: Write the basic SQL syntax for UNION ALL
A: SELECT column_name(s) FROM table1 UNION ALL SELECT column_name(s) FROM table2

Q: How does UNION ALL differ from UNION?
A: UNION removes duplicates; UNION ALL includes them

Q: Give an example query to return all cities from two tables using UNION ALL
A: SELECT City FROM Customers UNION ALL SELECT City FROM Suppliers ORDER BY City

Q: What happens if columns in SELECT statements for UNION ALL are not in the same order?
A: The query will not work

Q: Include duplicate German cities from Customers and Suppliers using UNION ALL (example)
A: SELECT City, Country FROM Customers WHERE Country='Germany' UNION ALL SELECT City, Country FROM Suppliers WHERE Country='Germany' ORDER BY City

Q: True or False: The number of columns in each SELECT must match in UNION ALL
A: True

Q: When should you use UNION ALL instead of UNION?
A: When you need all rows, including duplicates

Q: Reverse card—UNION ALL includes all duplicates. What operator is this describing?
A: UNION ALL operator

Q: Reverse card—UNION removes duplicate rows. Which SQL operator?
A: UNION operator

Q: Reverse card—Every SELECT in UNION ALL must have same columns, similar types, same order. Which requirement is described?
A: UNION ALL requirements

Q: Reverse card—SELECT City FROM Customers UNION ALL SELECT City FROM Suppliers ORDER BY City. What does this statement do?
A: Returns all cities (with duplicates) from Customers and Suppliers tables

Q: Reverse card—True. Must SELECT same number of columns in UNION ALL?
A: Is it a requirement to have the same number of columns in SELECT statements when using UNION ALL?